package com.wuyu.mini.dubbo.registry;

import com.wuyu.mini.dubbo.cluster.LoadBalance;
import com.wuyu.mini.dubbo.cluster.LoadBalanceFactory;
import com.wuyu.mini.dubbo.cluster.config.Config;
import java.util.List;

/**
 * 服务注册抽象
 */
public abstract class AbstractRegistry implements Registry{
    protected static final String FOLDER = "/mini-dubbo";
    protected static final String SEPARATOR = "/";

    public AbstractRegistry() {
        String address = Config.Registry.address;
        init(address);
    }

    public String discover(String service) {
        List<String> providers = lookup(service);
        LoadBalance loadbalance = LoadBalanceFactory.getLoadBalance();
        String select = loadbalance.select(providers);
        return select;
    }

    protected abstract void init(String address);

    protected abstract List<String> lookup(String service);
}
